/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Window 2.0
import QtQml.Models 2.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
import QtQml 2.12
import org.ukui.tablet 1.0
import org.ukui.qqc2style.private 1.0 as StylePrivate
import "createUninstallDialog.js" as UninstallJs
import "groupController.js" as GroupPageController
import "./baseComponent"
import "./LauncherViewComponent"
import "."

Item {
    id: root
    property var viewMoel: null
    property bool dragEnable: true
    property Item pluginAnchorItem: undefined
    property var pageContainer: listView
    property int groupId: -1
    property var appImage
    property var apptext
    property int appNameWidth: 128 * Style.tabletScaleFactor
    property alias taskBar: taskbar

    signal startDrag(bool started)
    signal titleFocusChanged()

    function listViewItemCount() {
        return listView.count
    }

    clip: false

    LauncherListView {
        id: listView
        signal movingChanged(bool m)
        highlightMoveDuration: 100
        maximumFlickVelocity: 8000
        onHorizontalVelocityChanged: movingChanged(horizontalVelocity)
    }

    Component {
        id: listViewItemDelegate
        TabletLauncherGridView {
        }
    }

    Component {
        id: gridviewItemDelegate
        TabletLauncherGridViewDelegate {
            id: delegateContent
        }
    }
    TaskBar {
        id: taskbar
        parentChange: root
        anchors.horizontalCenter: listView.horizontalCenter
        anchors.bottom: listView.bottom
        anchors.bottomMargin: 36 * Style.tabletScaleFactor
        onTaskbarItemEnterDesktop: {
            modelManager.addPlaceholderItem(modelManager.groupPageItemCount(-1, listView.currentIndex), listView.currentIndex)
            taskbarReplayAllowed = true
        }
        onTaskbarItemEnterTaskbar: {
            modelManager.removePlaceholderItem()
            taskbarReplayAllowed = false
        }
        onGroupItemEnterDesktop: {
            modelManager.addPlaceholderItem(modelManager.groupPageItemCount(-1, listView.currentIndex), listView.currentIndex)
        }
    }

    ParallelAnimation {
        running: GroupController.groupPopuped
        PropertyAnimation { target: listView; property: "scale"; from: 1; to: 0.9; easing.type: Easing.OutCubic; duration: 150; }
        PropertyAnimation { target: taskbar; property: "scale"; from: 1; to: 0.9; easing.type: Easing.OutCubic; duration: 150; }
    }
    ParallelAnimation {
        running: !GroupController.groupPopuped
        PropertyAnimation { target: listView; property: "scale"; from: 0.9; to: 1; easing.type: Easing.OutCubic; duration: 150; }
        PropertyAnimation { target: taskbar; property: "scale"; from: 0.9; to: 1; easing.type: Easing.OutCubic; duration: 150; }
    }
}






